perm filename CYCLIC.LSP[E80,JMC]1 blob
sn#531737 filedate 1980-08-27 generic text, type C, neo UTF8
COMMENT ā VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 functions for computing with cyclic list structures
C00004 ENDMK
Cā;
;;; functions for computing with cyclic list structures
(defun count (x) (car (count1 x nil)))
(defun count1 (x u) (if
(atom x) (cons 1 u)
(member x u) (cons 0 u)
((lambda (w) (foo (car w) (count1 (cdr x) (cdr w))))
(count1 (car x) (cons x u)))))
(defun foo (n u) (cons (+ n (car u)) (cdr u)))
(defun cycle1 (u v) (if (null (cdr u)) (rplacd u v) (cycle1 (cdr u) v)))
(defun cycle (u) (cycle1 u u))
((lambda (x) nil)(setq a (cycle '(a b c))))
(defun nodes1 (x u) (if (member x u) u
(atom x) (cons x u)
(nodes1 (cdr x) (nodes1 (car x) (cons x u)))))
(defun count2 (x) (length (nodes1 x nil)))